// 市场销售 / 任务设置

import r from '@/utils/request';
import type { ListResponseType, ResponseType } from '../types';

enum API {
    list = '/elderlyTaskList/task', //我的任务
    getTaskList = '/elderlyTask/getTask/',//获取老人任务列表
    taskForElderly = '/elderlyTaskList/taskForElderlyId',//我的任务详情
    del = '/elderlyTask/delete/', //删除任务
    add = '/elderlyTask/add', //添加任务
    updateState = '/elderlyTaskList/updateState', //修改任务状态

}
type getTaskResType = ListResponseType<{
    id: number;
    companyId: number;
    elderlyId: number;
    startTime: null | string;
    endTime: null | string;
    week: null | string;
    day: string[] | null;
    serviceId: number;
    type: string[] | null;
    serviceName: string[] | null;
    staffId: number;
    state: number;
}>
export interface elderlyTaskAddParams{
    elderlyId: number;
    serviceId: number;
    startTime: string;
    endTime: string;
    week: string;
    day: string;
    type: string;
}

type elderlyTaskAddResType = ListResponseType<{
    id:          number;
    companyId:   number;
    elderlyId:   number;
    startTime:   string;
    endTime:     string;
    week:        string;
    day:         string;
    serviceId:   number;
    type:        string;
    serviceName: string;
    staffId:     number;
    state:       number;
}>
export interface updateStateParams {
    state: number;
    ids:   string[];
}

export function getTaskListAPI(id: number): Promise<getTaskResType> {
    return r.get(API.getTaskList + id);
}
export function DelelderlyTaskAPI(id: number): Promise<ResponseType<null>> {
    return r.delete(API.del + id);
}
export function AddelderlyTaskAPI(data: elderlyTaskAddParams): Promise<elderlyTaskAddResType> {
    return r.post(API.add, data,{ timeout: 300000 });
}

export function updateStateAPI(data: updateStateParams): Promise<ResponseType<null>> {
    return r.post(API.updateState, data);
}